package com.three.crm.util;

import android.util.Log;

import com.three.crm.MyApplication;
import com.three.crm.constant.AppConstant;
import com.three.crm.http.CommonResultCallBack;
import com.three.crm.require.AppRequireService;

import org.json.JSONException;
import org.json.JSONObject;

import okhttp3.Call;

public class LogUtils {

    public static void onUploadLog(String message){
        JSONObject jsonObject = new JSONObject();
        try {
            jsonObject.put("userToken", AppManager.getToken());
            jsonObject.put("data",message);
            jsonObject.put("timestamp",AppManager.getTimesTamp());
            String sign = SignUtil.genSign(jsonObject);
            jsonObject.put("sign",sign);
            AppRequireService.uploadLog(MyApplication.getContext(), AppConstant.SAVE_LOG, jsonObject, new CommonResultCallBack(MyApplication.getContext()) {
                @Override
                public void onResult(String result, int requireCode) {
                    if (requireCode == AppConstant.SAVE_LOG) {
                        Log.i("TAG","上传日志成功！");
                    }
                }

                @Override
                public void onConnectTimeOut(Call call, Exception e, int requireCode) {

                }

                @Override
                public void onFail(String msg, int requireCode) {

                }
            });
        } catch (JSONException e) {
            e.printStackTrace();
        }
    }
}
